package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.AdvIncomedetail;
import com.ruoyi.service.IAdvIncomedetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/system/incomedetail")
public class AdvIncomedetailController extends BaseController
{
    @Autowired
    private IAdvIncomedetailService advIncomedetailService;

    /**
     * 查询列表
     */

    @PreAuthorize("@ss.hasPermi('system:incomedetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvIncomedetail advIncomedetail)
    {
        startPage();
        List<AdvIncomedetail> list = advIncomedetailService.selectAdvIncomedetailList(advIncomedetail);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */

    @PreAuthorize("@ss.hasPermi('system:incomedetail:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvIncomedetail advIncomedetail)
    {
        List<AdvIncomedetail> list = advIncomedetailService.selectAdvIncomedetailList(advIncomedetail);
        ExcelUtil<AdvIncomedetail> util = new ExcelUtil<AdvIncomedetail>(AdvIncomedetail.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */

    @PreAuthorize("@ss.hasPermi('system:incomedetail:query')")
    @GetMapping(value = "/{advIncomedetailId}")
    public AjaxResult getInfo(@PathVariable("advIncomedetailId") Long advIncomedetailId)
    {
        return success(advIncomedetailService.selectAdvIncomedetailByAdvIncomedetailId(advIncomedetailId));
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:incomedetail:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvIncomedetail advIncomedetail)
    {
        return toAjax(advIncomedetailService.insertAdvIncomedetail(advIncomedetail));
    }

    /**
     * 修改
     */

    @PreAuthorize("@ss.hasPermi('system:incomedetail:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvIncomedetail advIncomedetail)
    {
        return toAjax(advIncomedetailService.updateAdvIncomedetail(advIncomedetail));
    }

    /**
     * 删除
     */

    @PreAuthorize("@ss.hasPermi('system:incomedetail:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advIncomedetailIds}")
    public AjaxResult remove(@PathVariable Long[] advIncomedetailIds)
    {
        return toAjax(advIncomedetailService.deleteAdvIncomedetailByAdvIncomedetailIds(advIncomedetailIds));
    }

    /**
     * 收益明细
     */

    @GetMapping("/detail/{advIncomeId}")
    public TableDataInfo getIncomedetail(@PathVariable("advIncomeId") String advIncomeId) {
        startPage();
        List<AdvIncomedetail> list = advIncomedetailService.getIncomedetail(advIncomeId);
        return getDataTable(list);
    }
}
